package com.cgw.web.user.action;

import java.util.List;

import com.cgw.common.base.BaseAction;
import com.cgw.dmplt.common.PageBean;
import com.cgw.dmplt.user.dao.UserDao;
import com.cgw.dmplt.user.domain.User;

public class UserAction extends BaseAction {

	private User user;
	private PageBean<User> page;
	private Integer userId;
	
	public String doList(){
		UserDao userDao=(UserDao)getBean("userDao");
		try{
			if(user==null){
				user=new User();
			}
			List<User> userList=userDao.listUser(user);
			
			Integer count=userDao.listUserCount(user);
			
			page=new PageBean(userList,count,user.getCurentPage());
			
		}catch(Exception e){
			log.error("列表查询出错!", e);
		}
		return SUCCESS;
	}
	
	public String doQuery(){
		UserDao userDao=(UserDao)getBean("userDao");
		user=userDao.findUser(userId);
		return SUCCESS;
	}
	
	
	
	public String doDetail(){
		UserDao userDao=(UserDao)getBean("userDao");
		user=userDao.findUser(userId);
		
		return SUCCESS;
	}
	
	public String doUpdate(){
		UserDao userDao=(UserDao)getBean("userDao");
		
		userDao.updateUser(user);
		
		return doList();
	}
	
	
	public String doInsert(){
		UserDao userDao=(UserDao)getBean("userDao");
		userDao.insertUser(user);
		
		return doList();
	}
	

	
	public String doDelete(){
		UserDao userDao=(UserDao)getBean("userDao");
		userDao.deleteUser(user);
		user.clear(user.getClass(), user);
		
		return doList();
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public PageBean<User> getPage() {
		return this.page;
	}

	public void setPage(PageBean<User> page) {
		this.page = page;
	}

	public Integer getUserId() {
		return this.userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

}
